package com.start.common.entity;

import com.alibaba.fastjson2.JSONArray;
import com.start.common.dic.DictMapper;
import com.start.common.std.IStartUserKey;
import com.start.common.std.IStartUserType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

@Data
@EqualsAndHashCode(callSuper = true)
public abstract class StartBaseUser extends StartBaseEntity implements IStartUserType, IStartUserKey {
    private static final String DIC_SEX = "[" +
            "{\n" +
            "                    label: '未定义',\n" +
            "                    value: 0\n" +
            "                }, " +
            "{\n" +
            "                    label: '男',\n" +
            "                    value: 1\n" +
            "                }, " +
            "{\n" +
            "                    label: '女',\n" +
            "                    value: 2\n" +
            "                }]" ;
    private static final String DIC_IS_LOCKED = "[" +
            "{\n" +
            "                    label: '未锁定',\n" +
            "                    value: 0\n" +
            "                }, " +
            "{\n" +
            "                    label: '已锁定',\n" +
            "                    value: 1\n" +
            "                }] " ;
    private static final String DIC_IS_ENABLE = "[" +
            "{\n" +
            "                    label: '未锁定',\n" +
            "                    value: 0\n" +
            "                }, " +
            "{\n" +
            "                    label: '已锁定',\n" +
            "                    value: 1\n" +
            "                }] " ;


    @Schema(name = "用户名")
    @DictMapper("用户名")
    private String userName;
    @Schema(name = "用户密码")
    private String userPwd;
    @Schema(name = "头像地址")
    @DictMapper("头像地址")
    private JSONArray avatar;
    @Schema(name = "性别", description = "0 未定义 1男 2女")
    @DictMapper(value = "性别", mapperStatic = DIC_SEX)
    private Integer sex;
    @Schema(name = "昵称")
    @DictMapper("昵称")
    private String nickName;
    @Schema(name = "真实姓名")
    @DictMapper("真实姓名")
    private String realName;
    @Schema(name = "账号是否被锁定", description = "0 未锁定 1已锁定")
    @DictMapper(value = "否被锁定", mapperStatic = DIC_IS_LOCKED)
    private Integer isLocked;
    @Schema(name = "账号是否启用", description = "0 未启用 1已启用")
    @DictMapper(value = "是否启用", mapperStatic = DIC_IS_ENABLE)
    private Integer isEnabled;
    @Schema(name = "用户类型")
    private String userType;


    public String getUserFinalName() {
        if (!StringUtils.isEmpty(realName)) {
            return realName;
        } else if (!StringUtils.isEmpty(nickName)) {
            return nickName;
        } else {
            return userName;
        }
    }


}
